import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/'
import moment from 'moment'
import './components/css/all.css'
// 'development',use package;'production':use cdn;
import ElementUI from 'element-ui'
import JsonExcel from 'vue-json-excel'
import "@/assets/fonts/style.css"
import "./assets/iconfont/iconfont.css"
import 'viewerjs/dist/viewer.css'
import VueViewer from 'v-viewer'
import VueParticles from 'vue-particles'
Vue.use(ElementUI, { size: 'mini' });
VueViewer.setDefaults({
  zIndex:9999,
  zIndexInline:9999
})
Vue.use(VueViewer)
Vue.use(VueParticles)
import('element-ui/lib/theme-chalk/index.css')
import WebSocketClient from './utils/websocket.js'
import { createVersionPolling } from "version-polling";
import './style/variables.less'
import './style/globaltable.css'


router.onError((error) => {
  const pattern = /Loading chunk (\d)+ failed/g;
  const isChunkLoadFailed = error.message.match(pattern);
  const targetPath = router.history.pending.fullPath;
  if (isChunkLoadFailed) {
    // router.replace(targetPath);
    location.reload();
  }
});
//echarts

import echarts from '@/utils/echartsUI'
Vue.prototype.$echarts = echarts

//websocket连接
Vue.prototype.$socket = {};
function connectWebSocket() {
  let url;
  if (window.location.origin == "https://tms.dushisc.com") {
    url = 'wss://tmsapi.dushisc.com/socket/system/message'; // WebSocket 服务器地址
  } else {
    url = 'ws://101.200.164.94:9997/socket/system/message'; // WebSocket 服务器地址
  }
  const socket = new WebSocketClient(url);
  socket.connect();
  Vue.prototype.$socket = socket;
}
connectWebSocket();



import './components/iconSvg' // iconSvg

import '@/permission' // permission control

import '@/mockjs'; // mock数据

import VueAMap from 'vue-amap';
Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
  // 897846c7ce0b58b5a56c645ce12cde3f
  key: '897846c7ce0b58b5a56c645ce12cde3f',
  // 9aaf5fed31734197b290addfc9fba848
  // securityJsCode:'9aaf5fed31734197b290addfc9fba848',
  plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor', 'AMap.MouseTool', 'AMap.Geocoder', 'AMap.Geolocation'],
  v: '1.4.4', // 高德sdk版本，最新的sdk已经出到了2.0
})
window._AMapSecurityConfig = {
  securityJsCode: '9aaf5fed31734197b290addfc9fba848',
}
createVersionPolling({
  appETagKey: "__APP_ETAG__",
  pollingInterval: 60 * 1000, // 单位为毫秒
  silent: process.env.NODE_ENV === "development", // 开发环境下不检测
  onUpdate: (self) => {
    // 当检测到有新版本时，执行的回调函数，可以在这里提示用户刷新页面
    self.onRefresh();
  },
});

import Print from 'vue-print-nb'
Vue.use(Print)

// 指引
import VueTour from 'vue-tour'
require('vue-tour/dist/vue-tour.css')
Vue.use(VueTour)

// i18n国际化
import i18n from "@/lang";

// 分享功能集合
import { shareConfig } from './utils/share';
Vue.prototype.shareConfig = shareConfig;

// 自定义指令
import directive from '@/directive';
Vue.use(directive);


Vue.prototype.$moment = moment;
moment.locale('zh-cn');//需要汉化
Vue.config.productionTip = false;
Vue.component('downloadExcel', JsonExcel)


import Tracker from './tracker'
new Tracker();
// 解决 两个窗口打开页面，一个换账号需要刷新页面
window.addEventListener("visibilitychange", function () {
  try {
    const storeUserId = store.state.user.user_id;//vuex里面保存的账号id
    const localUserId = (JSON.parse(localStorage.getItem("user")) || {}).user_id;//登录时的账号id
    if (storeUserId&&localUserId&&document.hidden === false && storeUserId !== localUserId) {
      window.location.reload();
    }
  } catch (e) { }
})
// const VUE_APP_VERSION = require('../package.json').version
// const vers = window.localStorage.getItem("appVersion");
window.localStorage.setItem("appVersion", '2.0.1');
// // console.log(VUE_APP_VERSION,"VUE_APP_VERSION")
// if (VUE_APP_VERSION != vers) {
//   localStorage.clear()
//   window.localStorage.setItem("appVersion", VUE_APP_VERSION);
//   location.reload()
// }
new Vue({
  router,
  store,
  i18n, // 便于可以直接在组件中通过this.$i18n使用，也可以按需引用
  render: h => h(App),
}).$mount('#app')